import java.util.ArrayList;
import java.util.List;

public class ClassLock {
    private static List<String> result=new ArrayList<>();
    private Object lock = new Object();
    public static void main(String[] args) {
        ClassLock classLock1 = new ClassLock();
        ClassLock classLock2 = new ClassLock();
        new Thread(() -> classLock1.lock()).start();
        new Thread(() -> classLock2.lock()).start();
    }

    public  void lock() {
        int i = 0;
        synchronized (lock){
            do {
                try {
                    result.add(""+i);
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println( " is locked " + i);
            } while (i++ < 10);
        }
    }
}